package org.apache.ibatis.common.logging.slf4j;

import org.apache.ibatis.common.logging.Log;
import org.apache.ibatis.common.logging.LogFactory;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import org.slf4j.spi.LocationAwareLogger;

/**
 * @Name Slf4jLocationAwareLoggerImpl
 * @Description: Slf4jImpl 具体实现类
 * @Version v1.0.0
 * @Author: lichao
 * @Date: 2024-05-15 16:00:21
 **/
public class Slf4jLocationAwareLoggerImpl implements Log {
    private static final Marker MARKER = MarkerFactory.getMarker(LogFactory.MARKER);
    private static final String FQCN = Slf4jImpl.class.getName();
    private final LocationAwareLogger logger;

    public Slf4jLocationAwareLoggerImpl(LocationAwareLogger logger) {
        this.logger = logger;
    }

    @Override
    public boolean isDebugEnabled() {
        return logger.isDebugEnabled();
    }

    @Override
    public boolean isTraceEnbaled() {
        return logger.isTraceEnabled();
    }

    @Override
    public void error(String msg, Throwable e) {
        logger.log(MARKER, FQCN, LocationAwareLogger.ERROR_INT, msg, null, e);
    }

    @Override
    public void error(String msg) {
        logger.log(MARKER, FQCN, LocationAwareLogger.ERROR_INT, msg, null, null);
    }

    @Override
    public void warn(String msg) {
        logger.log(MARKER, FQCN, LocationAwareLogger.WARN_INT, msg, null, null);
    }

    @Override
    public void debug(String msg) {
        logger.log(MARKER, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, null);
    }

    @Override
    public void trace(String msg) {
        logger.log(MARKER, FQCN, LocationAwareLogger.TRACE_INT, msg, null, null);
    }
}

